﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DreamBuilder.Common;
using ePlanet.ResourceRequest.Services;
using ePlanet.ResourceRequest.DataAccess;
using ePlanet.ResourceRequest.Models;
using Web.SystemConfig;
using Web.SystemConfig.WorkFlow;
using System.Data;

namespace ePlanet.ResourceRequest.Business
{
    public class BUSResourceRequest : BusinessBase, IResourceRequestService
    {
        private ResourceRequestDAL m_ResourceRequestDAL = null;

        public BUSResourceRequest()
        {
            if (this.m_ResourceRequestDAL == null)
            {
                this.m_ResourceRequestDAL = new ResourceRequestDAL();
            }
        }

        public void ApplyNewRequest(Models.ResourceRequestModel requestModel)
        {
            this.m_ResourceRequestDAL.AddNewResourceRequest(requestModel);
        }

        public void AgreeRequest(Models.ResourceRequestModel requestModel)
        {
            this.m_ResourceRequestDAL.AgreeRequest(requestModel);
        }

        public void AgreeRequest(List<Guid> idList)
        {
            foreach (Guid id in idList)
            {
                this.m_ResourceRequestDAL.AgreeRequest(id);
            }
        }

        public void DisAgreeRequest(List<Guid> idList)
        {
            foreach (Guid id in idList)
            {
                this.m_ResourceRequestDAL.DisAgreeRequest(id);
            }
        }

        public void DisAgreeRequest(Models.ResourceRequestModel requestModel)
        {
            this.m_ResourceRequestDAL.DisAgreeRequest(requestModel);
        }

        public System.Data.DataTable GetRequestList(DataAccess.ResourceRequestEnum requestEnum, string userID)
        {
            return this.m_ResourceRequestDAL.GetRequestList(requestEnum, userID);
        }

        public System.Data.DataTable GetRequestList(DataAccess.ResourceRequestEnum requestEnum, string userID, string wellDataID)
        {
            return this.m_ResourceRequestDAL.GetRequestList(requestEnum, userID, wellDataID);
        }

        public DataTable GetRequestListByWellDataID(ResourceRequestEnum requestEnum, string wellDataID)
        {
            return this.m_ResourceRequestDAL.GetRequestListByWellDataID(requestEnum, wellDataID);
        }


        public bool GetPrivilege(string dataID, string userID, ref bool canView, ref bool canDownload)
        {
            return this.m_ResourceRequestDAL.GetPrivilege(dataID, userID, ref canView, ref canDownload);
        }

        public bool HasNoExpiredRequest(string dataID, string userID)
        {
            return this.m_ResourceRequestDAL.HasNoExpiredRequest(dataID, userID);
        }

        public ResourceRequestModel GetResourceRequestModelByID(string ID)
        {
            return this.m_ResourceRequestDAL.GetResourceRequestModelByID(ID);
        }

        public DataTable GetDone(string userID, string wellTypeID)
        {
            return this.m_ResourceRequestDAL.GetDone(userID, wellTypeID);
        }

        public DataTable QueryAgent(ResourceRequestEnum requestEnum, int pageIndex, int pageSize, out int sum)
        {
            return this.m_ResourceRequestDAL.QueryAgent(requestEnum, pageIndex, pageSize, out sum);
        }

        public DataTable QueryDone(int pageIndex, int pageSize, out int sum)
        {
            return this.m_ResourceRequestDAL.QueryDone(pageIndex, pageSize, out sum);
        }
    }
}